package com.shop.item.mapper;

import com.shop.common.mapper.BaseMapper;
import com.shop.item.pojo.Brand;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author : Created by HGL on 2019/03/16 13:01
 * @version : 1.0
 * Description :
 */
public interface BrandMapper extends BaseMapper<Brand> {
    /**
     * 新增商品分类和品牌中间表数据
     *
     * @param cid 商品分类id
     * @param bid 品牌id
     * @return
     */
    @Insert("INSERT INTO tb_category_brand (category_id, brand_id) VALUES (#{cid},#{bid})")
    int insertCategoryBrand(@Param("cid") Long cid, @Param("bid") Long bid);

    @Select("SELECT b.id,b.name,b.letter,b.image FROM tb_brand b INNER JOIN tb_category_brand cd ON b.id = cd.brand_id WHERE cd.category_id =#{cid}")
    List<Brand> queryByCategoryId(@Param("cid") Long cid);
}
